<style lang='less' scoped>
img {
  width: 100px;
}
.box{
  ul{
    li{
      display: flex;
      line-height: 100px;
      button{
        width: 30px;
        
      }
    }
  }
}
</style>
<template>
  <div>
    <div class="box">
      <ul>
        <li v-for="item in goods_arr" :key="item.id">
          <input
            type="checkbox"
            :checked="item.status"
            @click="item.status = !item.status"
          />
          <img :src="item.img" alt="" />
          <span>{{ item.name }}</span>
          <span>{{ item.price }}</span>
          <div>
            <button @click="item.num--" :disabled="item.num <= 1">-</button>
            <span>{{ item.num }}</span>
            <button @click="item.num++">+</button>
          </div>
        </li>
      </ul>
      <div>
        总价: <span>{{ priceAll }}</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      goods_arr: [],
    };
  },
  methods: {},
  computed: {
    priceAll() {
      let number = 0;
      this.goods_arr.forEach((item) => {
        if (item.status) {
          number += item.price * item.num;
        }
      });
      return parseFloat(number);
    },
  },
  mounted() {
    this.goods_arr = JSON.parse(localStorage.getItem("medicine"));
  },
};
</script>